package hight;

import java.util.concurrent.locks.LockSupport;

public class LockSupportTest1 {
    public static void main(String[] args) {


        Thread t = new Thread(() -> {
            System.out.println(Thread.currentThread().isInterrupted() + "start run");
            // 调用线程的interrupt也会导致park被终端，当发生终端时执行自定义操作
            LockSupport.park();
            if (Thread.currentThread().isInterrupted()) {
                System.out.println(Thread.currentThread().getName() + "is interrupted ");
                LockSupport.park();
            }
            System.out.println(Thread.currentThread().getName() + " stop run");

        });
        t.start();
        try {
            Thread.sleep(2000);
            // 调用线程的interrupt也会导致park被终端，但是差别时他不抛出InterruptedException
            t.interrupt();
            t.join();
            System.out.println(Thread.currentThread().getName()+" stop run");
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
